package com.yyydjk.library;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created by xujl on 2017/12/14.
 */

public class DefaultTabView extends TextView implements ITabView<String> {
    //tab字体大小
    private int menuTextSize = 35;

    //tab选中图标
    private int menuSelectedIcon;
    //tab未选中图标
    private int menuUnselectedIcon;
    //tab选中颜色
    private int textSelectedColor = 0xff890c85;
    //tab未选中颜色
    private int textUnselectedColor = 0xff111111;
    public DefaultTabView (Context context) {
        super(context);
        init();
    }

    public DefaultTabView (Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public DefaultTabView (Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public DefaultTabView (Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    private void init () {
        menuUnselectedIcon = com.yyydjk.library.R.mipmap.drop_down_unselected_icon;
        menuSelectedIcon = com.yyydjk.library.R.mipmap.drop_down_selected_icon;
        setSingleLine();
        setEllipsize(TextUtils.TruncateAt.END);
        setGravity(Gravity.CENTER);
        setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize);
        setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));
        setTextColor(textUnselectedColor);
        setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(menuUnselectedIcon), null);
        setPadding(DeviceUtils.dpTpPx(5, getContext()), DeviceUtils.dpTpPx(12, getContext())
                , DeviceUtils.dpTpPx(5, getContext()), DeviceUtils.dpTpPx(12, getContext()));
    }

    @Override
    public void setTabContent (String data) {
        setText(data);
    }

    @Override
    public void setClickListener (OnClickListener onClickListener) {
        setOnClickListener(onClickListener);
    }

    @Override
    public void checked () {
        setTextColor(textSelectedColor);
        setCompoundDrawablesWithIntrinsicBounds(null, null,
                getResources().getDrawable(menuSelectedIcon), null);
    }

    @Override
    public void unChecked () {
        setTextColor(textUnselectedColor);
        setCompoundDrawablesWithIntrinsicBounds(null, null,
                getResources().getDrawable(menuUnselectedIcon), null);
    }


}
